home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / pslatex.trm (.txt) < prev    next >
LaTeX Document  |  1993-09-15  |  5KB  |  171 lines

  1.  * $Id: pslatex.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  2. /* GNUPLOT - pslatex.trm */
  3.  * Copyright (C) 1990 - 1993   
  4.  * Permission to use, copy, and distribute this software and its
  5.  * documentation for any purpose with or without fee is hereby granted, 
  6.  * provided that the above copyright notice appear in all copies and 
  7.  * that both that copyright notice and this permission notice appear 
  8.  * in supporting documentation.
  9.  * Permission to modify the software is granted, but not the right to
  10.  * distribute the modified code.  Modifications are to be distributed 
  11.  * as patches to released version.
  12.  * This software  is provided "as is" without express or implied warranty.
  13.  * This file is included by ../term.c.
  14.  * This terminal driver supports:
  15.  *     latex with embedded postscript
  16.  * AUTHORS
  17.  *  George Phillips
  18.  *  Russell Lang
  19.  *  David Kotz
  20.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  21. /* Driver by George Phillips */
  22. #define PSLATEX_XMAX (5*720)
  23. #define PSLATEX_YMAX (3*720)
  24. /* 10 pt char is about 10 pts high (say) */
  25. #define PSLATEX_VCHAR (100)
  26. /* 10 pt char is about 6 pts wide (say) */
  27. #define PSLATEX_HCHAR (60)
  28. static int PSLATEX_angle;
  29. static int PSLATEX_justify;
  30. static int PSLATEX_rotate = TRUE;
  31. struct text_command {
  32.     int x, y, angle, justify;
  33.     char* label;
  34.     struct text_command* next;
  35. static struct text_command* PSLATEX_labels;
  36. PSLATEX_options()
  37.     if (!END_OF_COMMAND) {
  38.     if (almost_equals(c_token, "d$efault")) {
  39.         ps_color = FALSE;
  40.         PSLATEX_rotate = TRUE;
  41.         c_token++;
  42.     }
  43.     if (!END_OF_COMMAND) {
  44.     if (almost_equals(c_token, "c$olor")) {
  45.         ps_color = TRUE;
  46.         c_token++;
  47.     }
  48.     if (!END_OF_COMMAND) {
  49.     if (almost_equals(c_token, "m$onochrome")) {
  50.         ps_color = FALSE;
  51.         c_token++;
  52.     }
  53.     if (!END_OF_COMMAND) {
  54.     if (almost_equals(c_token, "r$otate")) {
  55.         PSLATEX_rotate = TRUE;
  56.         c_token++;
  57.     }
  58.     if (!END_OF_COMMAND) {
  59.     if (almost_equals(c_token, "n$orotate")) {
  60.         PSLATEX_rotate = FALSE;
  61.         c_token++;
  62.     }
  63.     sprintf(term_options, "%s %s", ps_color ? "color" : "monochrome",
  64.     PSLATEX_rotate ? "rotate" : "norotate");
  65. PSLATEX_init()
  66.     /* reset PostScript driver variables */
  67.     ps_portrait = TRUE;
  68.     ps_eps = FALSE;
  69.     ps_color = FALSE;
  70.     fprintf(outfile, "%% GNUPLOT: LaTeX picture with Postscript\n");
  71.     fprintf(outfile, "\\setlength{\\unitlength}{0.1bp}\n");
  72.     fprintf(outfile, "\\special{!\n");
  73.     PS_init();
  74.     fprintf(outfile, "}\n");
  75.     PSLATEX_angle = 0;
  76.     PSLATEX_justify = 0;
  77.     PSLATEX_labels = 0;
  78. PSLATEX_scale(xs, ys)
  79. double xs, ys;
  80.     register struct termentry *t = &term_tbl[term];
  81.     t->xmax = (unsigned int)(PSLATEX_XMAX * xs);
  82.     t->ymax = (unsigned int)(PSLATEX_YMAX * ys);
  83.     return TRUE;
  84. PSLATEX_graphics()
  85.     struct termentry *t = &term_tbl[term];
  86.     fprintf(outfile, "\\begin{picture}(%d,%d)(0,0)\n", t->xmax, t->ymax);
  87.     fprintf(outfile, "\\special{\"\n");
  88.     PS_graphics();
  89.     /* thwart the translation done by PS_graphics() */
  90.     fprintf(outfile, "%f %f translate\n",
  91.         -PS_XOFF * (float)PS_SC, -PS_YOFF * (float)PS_SC);
  92.     PSLATEX_labels = (struct text_command *)NULL;
  93. PSLATEX_put_text(x, y, str)
  94. int x, y;
  95. char str[];
  96.     struct text_command* tc;
  97.     /* ignore empty strings */
  98.     if (str[0] == '\0')
  99.     return(0);
  100.     tc = (struct text_command*)alloc(sizeof(struct text_command),"pslatex");
  101.     tc->x = x;
  102.     tc->y = y;
  103.     tc->label = (char *)alloc(strlen(str) + 1,"pslatex");
  104.     strcpy(tc->label, str);
  105.     tc->justify = PSLATEX_justify;
  106.     tc->angle = PSLATEX_angle;
  107.     tc->next = PSLATEX_labels;
  108.     PSLATEX_labels = tc;
  109. PSLATEX_justify_text(mode)
  110. enum JUSTIFY mode;
  111.     PSLATEX_justify = mode;
  112.     return TRUE;
  113. int PSLATEX_text_angle(angle)
  114. int angle;
  115.     /* rotated text is put in a short stack, and optionally uses 
  116.      * postscript specials depending on PSLATEX_rotate */
  117.     PSLATEX_angle = angle;
  118.     return TRUE;
  119. PSLATEX_reset()
  120. PSLATEX_text()
  121.     struct text_command* tc;
  122.     PS_text();
  123.     fprintf(outfile, "}\n");
  124.     for (tc = PSLATEX_labels; tc != (struct text_command*)NULL; tc = tc->next) {
  125.     fprintf(outfile, "\\put(%d,%d){", tc->x, tc->y);
  126.     switch (tc->angle) {
  127.     case 0:
  128.         switch (tc->justify) {
  129.         case LEFT:
  130.         fprintf(outfile, "\\makebox(0,0)[l]{%s}", tc->label);
  131.         break;
  132.         case CENTRE:
  133.         fprintf(outfile, "\\makebox(0,0){%s}", tc->label);
  134.         break;
  135.         case RIGHT:
  136.         fprintf(outfile, "\\makebox(0,0)[r]{%s}", tc->label);
  137.         break;
  138.         }
  139.         break;
  140.     case 1: /* put text in a short stack */
  141.         if (PSLATEX_rotate) {
  142.             fprintf(outfile, "%%\n\\special{ps: gsave currentpoint currentpoint translate\n");
  143.             fprintf(outfile, "270 rotate neg exch neg exch translate}%%\n");
  144.         }
  145.         switch (tc->justify) {
  146.         case LEFT:
  147.         fprintf(outfile, "\\makebox(0,0)[lb]{\\shortstack{%s}}",
  148.             tc->label);
  149.         break;
  150.         case CENTRE:
  151.         fprintf(outfile, "\\makebox(0,0)[b]{\\shortstack{%s}}",
  152.             tc->label);
  153.         break;
  154.         case RIGHT:
  155.         fprintf(outfile, "\\makebox(0,0)[lt]{\\shortstack{%s}}",
  156.             tc->label);
  157.         break;
  158.         }
  159.         if (PSLATEX_rotate) {
  160.             fprintf(outfile, "%%\n\\special{ps: currentpoint grestore moveto}%%\n");
  161.         }
  162.     fprintf(outfile, "}\n");
  163.     }
  164.     while (PSLATEX_labels) {
  165.     tc = PSLATEX_labels->next;
  166.     free(PSLATEX_labels->label);
  167.     free(PSLATEX_labels);
  168.     PSLATEX_labels = tc;
  169.     }
  170.     fprintf(outfile, "\\end{picture}\n");
  171.